<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram - Flatcar and Men</title>
</head>
<body>

<canvas id="physicsCanvas" width="500" height="320" style="border:1px solid #000;"></canvas>

<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';

    // Function to draw a stick figure
    function drawStickFigure(x, feetLevel) {
        const figureHeight = 40;
        const headRadius = 6;

        // Feet/Base
        ctx.save();
        ctx.fillStyle = 'black';
        ctx.fillRect(x - 8, feetLevel - 3, 16, 3);
        ctx.restore();

        // Legs
        const bodyBottomY = feetLevel - 10;
        ctx.beginPath();
        ctx.moveTo(x, bodyBottomY);
        ctx.lineTo(x - 8, feetLevel - 3);
        ctx.moveTo(x, bodyBottomY);
        ctx.lineTo(x + 8, feetLevel - 3);
        ctx.stroke();

        // Body
        const bodyTopY = feetLevel - figureHeight + (2 * headRadius);
        ctx.beginPath();
        ctx.moveTo(x, bodyTopY);
        ctx.lineTo(x, bodyBottomY);
        ctx.stroke();

        // Arms
        const armY = bodyTopY + 6;
        ctx.beginPath();
        ctx.moveTo(x - 10, armY);
        ctx.lineTo(x + 10, armY);
        ctx.stroke();

        // Head
        const headY = feetLevel - figureHeight + headRadius;
        ctx.beginPath();
        ctx.arc(x, headY, headRadius, 0, 2 * Math.PI);
        ctx.fill();

        return headY; // Return y-coordinate of head center for label positioning
    }

    // Ground
    const groundY = 270;
    ctx.beginPath();
    ctx.moveTo(10, groundY);
    ctx.lineTo(490, groundY);
    ctx.stroke();

    // Ground hatches
    ctx.save();
    ctx.lineWidth = 1.5;
    for (let i = 15; i < 490; i += 20) {
        ctx.beginPath();
        ctx.moveTo(i, groundY);
        ctx.lineTo(i - 10, groundY + 10);
        ctx.stroke();
    }
    ctx.restore();

    // Base plank (lower part of the system)
    const baseY = 250;
    const baseHeight = 20;
    const baseStartX = 50;
    const baseWidth = 400;
    
    ctx.save();
    // Draw outer rectangle and fill with white
    ctx.fillStyle = 'white';
    ctx.fillRect(baseStartX, baseY, baseWidth, baseHeight);
    ctx.strokeRect(baseStartX, baseY, baseWidth, baseHeight);
    // Draw gray inner part to mimic shading
    ctx.fillStyle = '#E0E0E0';
    ctx.fillRect(baseStartX, baseY + 4, baseWidth, baseHeight - 8);
    ctx.restore();

    // Rollers
    const rollerRadius = 10;
    const rollerY = baseY - rollerRadius;
    const roller1X = 150;
    const roller2X = 350;
    
    ctx.save();
    ctx.fillStyle = 'white';
    ctx.beginPath();
    ctx.arc(roller1X, rollerY, rollerRadius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.stroke();
    
    ctx.beginPath();
    ctx.arc(roller2X, rollerY, rollerRadius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.stroke();
    ctx.restore();

    // Top plank (flatcar)
    const carHeight = 15;
    const carY = rollerY - rollerRadius - carHeight;
    const carStartX = 40;
    const carWidth = 420;
    
    ctx.save();
    ctx.fillStyle = 'white';
    ctx.fillRect(carStartX, carY, carWidth, carHeight);
    ctx.strokeRect(carStartX, carY, carWidth, carHeight);
    ctx.restore();

    // Stick Figures
    const figureFeetLevel = carY;
    const figure1X = 180;
    const figure2X = 320;
    const headY1 = drawStickFigure(figure1X, figureFeetLevel);
    const headY2 = drawStickFigure(figure2X, figureFeetLevel);

    // Label N
    ctx.font = '24px serif';
    const labelNX = (figure1X + figure2X) / 2;
    const labelNY = headY1 - 15;
    ctx.fillText('N', labelNX - 7, labelNY);
    
    // Dashed line for N
    ctx.save();
    ctx.beginPath();
    ctx.setLineDash([5, 3]);
    ctx.lineWidth = 1;
    ctx.moveTo(figure1X + 15, headY1);
    ctx.lineTo(figure2X - 15, headY2);
    ctx.stroke();
    ctx.restore();

    // Figure label
    ctx.font = '22px serif';
    ctx.fillText('Fig. 1.86.', 210, 310);

</script>

</body>
</html>